package com.o2o.app.service;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;

import com.o2o.app.R;
import com.o2o.app.adapter.CommentListAdapter;
import com.o2o.app.bean.NewspaperBean;
import com.o2o.app.views.RefreshListView;
import com.o2o.app.views.RefreshListView.ILoadMoreViewState;
import com.o2o.app.views.RefreshListView.IOnLoadMoreListener;
import com.o2o.app.views.RefreshListView.IOnRefreshListener;

public class BQNewspaperActivity extends Activity implements
		IOnRefreshListener, IOnLoadMoreListener, OnItemClickListener {

	private RefreshListView rlv_comment;
	private ArrayList<NewspaperBean> newList = new ArrayList<NewspaperBean>();
	private CommentListAdapter adapter;

	private int max = 3;
	private NewspaperBean bean;

	/**
	 * 返回
	 */
	private Button btn_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.bq_newspaper);

		initView();
		initData();
	}

	private void initView() {
		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new ClickEvent());

		rlv_comment = (RefreshListView) findViewById(R.id.rlv_comment);

		adapter = new CommentListAdapter(this, newList);
		rlv_comment.setAdapter(adapter);
		rlv_comment.setOnRefreshListener(this);// 刷新事件
		rlv_comment.setOnLoadMoreListener(this);// 分页加载事件
		rlv_comment.setOnItemClickListener(this);
	}

	private void initData() {
		bean = new NewspaperBean();
		bean.setCommunity("北苑分社");
		bean.setTime("12:00");
		bean.setTitle("不少社区广场舞按下“静音键”");
		bean.setDes("闲置23寸高清液晶宽屏显示器转让,有九五成新，显示效果特别好，非常清晰，一点问题没有，需要的可以联系我！");

		for (int i = 0; i < max; i++) {
			newList.add(bean);
		}
		adapter.notifyDataSetChanged();// 更新list
		rlv_comment.onRefreshComplete();
		rlv_comment.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 显示“查看更多”
	}

	/**
	 * 点击事件
	 * 
	 * @author Administrator
	 * 
	 */
	class ClickEvent implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btn_back: { // 返回
				finish();
			}
				break;
			default:
				break;
			}
		}

	}

	@Override
	public void OnLoadMore() {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnRefresh() {
		// TODO Auto-generated method stub
		for (int i = 0; i < max; i++) {
			newList.add(bean);
		}
		adapter.notifyDataSetChanged();// 更新list
		rlv_comment.onRefreshComplete();
		rlv_comment.onLoadMoreComplete(ILoadMoreViewState.LMVS_NORMAL);// 显示“查看更多”
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub

	}
}
